blob: a1af9616ea115a3686ce09a06853a8efc8adefa2 [file] [log] [blame]
Nicolás Peña Morenocf8e8812019-04-01 17:12:021<!DOCTYPE HTML>
2<meta charset=utf-8>
3<title>Element Timing: observe a rectangular image</title>
4<body>
5<style>
6body {
7 margin: 20px;
8}
9</style>
10<script src="/resources/testharness.js"></script>
11<script src="/resources/testharnessreport.js"></script>
12<script src="resources/element-timing-helpers.js"></script>
13<script>
14 let beforeRender;
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5815 let img;
Nicolás Peña Morenocf8e8812019-04-01 17:12:0216 async_test(function (t) {
17 const observer = new PerformanceObserver(
18 t.step_func_done(function(entryList) {
19 assert_equals(entryList.getEntries().length, 1);
20 const entry = entryList.getEntries()[0];
21 const index = window.location.href.lastIndexOf('/');
22 // Subtracting 14 to remove 'element-timing'.
23 const pathname = window.location.href.substring(0, index - 14) +
24 'images/black-rectangle.png';
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5825 checkElement(entry, pathname, 'my_image', 'rectangle', beforeRender, img);
Nicolás Peña Morenocf8e8812019-04-01 17:12:0226 // Assume viewport has size at least 100, so the element is fully visible.
27 checkRect(entry, [20, 120, 20, 70]);
28 checkNaturalSize(entry, 100, 50);
29 })
30 );
31 observer.observe({entryTypes: ['element']});
32 // We add the image during onload to be sure that the observer is registered
33 // in time for it to observe the element timing.
34 window.onload = () => {
35 // Add image of width equal to 100 and height equal to 50.
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5836 img = document.createElement('img');
Nicolás Peña Morenocf8e8812019-04-01 17:12:0237 img.src = '/images/black-rectangle.png';
Nicolás Peña Moreno15d28552019-04-01 19:03:0838 img.id = 'rectangle';
Nicolás Peña Morenocf8e8812019-04-01 17:12:0239 img.setAttribute('elementtiming', 'my_image');
40 document.body.appendChild(img);
41 beforeRender = performance.now();
42 };
43 }, 'Element with rectangular image has correct rect and instrinsic size.');
44</script>
45</body>